﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Symbonix.NorSoNet.Framework;
using Symbonix.NorSoNet.Security.BLL;
using Symbonix.NorSoNet.Security.BLL.Membership;

public partial class RecoverPassword : PublicBasePage
{
    private Guid ActivationKey
    {
        get
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["key"]))
                    return new Guid(Request.QueryString["key"].ToString());
                else
                    return new Guid("");
            }
            catch
            {
                return  new Guid("");
            }
        }
    }


    private string Email
    {
        get
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["email"]))
                    return Server.HtmlDecode(Request.QueryString["email"].ToString());
                else
                    return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlRecoveryFirstStep.Visible = false;
            pnlRecoverySecondStep.Visible = false;

            if (string.IsNullOrEmpty(Email))
            {
                pnlRecoveryFirstStep.Visible = true;
            }
            else
            {
                pnlRecoverySecondStep.Visible = true;
            }
        }
    }
    protected void btnSendRecoverMail_Click(object sender, EventArgs e)
    {

        Workflow workflow = new Workflow();
        workflow.SendPasswordRecoveryLink(txtUserName.Text);

    }

    protected void btnChangePassword_Click(object sender, EventArgs e)
    {
        Workflow workflow = new Workflow();
        
        bool isPasswordChanged = workflow.ChangePassword(ActivationKey, Email, txtConfirmPassword.Text);
        if (isPasswordChanged)
        {
            lblNotifier.Text = "You Successfully changeed your password please login with your new password";
        }



    }
}
